package com.qf.shopping.service.impl;

import com.qf.shopping.dto.MessageDTO.MessageDTO;
import com.qf.shopping.dto.MessageDTO.MessageProfileDTO;
import com.qf.shopping.dto.memberDTO.MemberPointDTO;
import com.qf.shopping.mapper.IAdminMangerMapper;
import com.qf.shopping.mapper.IMessageMapper;
import com.qf.shopping.dto.memberDTO.MemberDTO;
import com.qf.shopping.dto.memberDTO.MemberProfileDTO;
import com.qf.shopping.pojo.System.User;
import com.qf.shopping.pojo.member.Member;
import com.qf.shopping.pojo.member.MemberCar;
import com.qf.shopping.pojo.member.MemberPoint;
import com.qf.shopping.pojo.member.MemberProfile;
import com.qf.shopping.pojo.message.Message;
import com.qf.shopping.service.MemberService;
import com.qf.shopping.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;



@Service
@Transactional
public class MessageSeviceImpl implements MessageService {

   @Autowired
   private IMessageMapper iMessageMapper=null;

   @Autowired
    private  IAdminMangerMapper iAdminMangerMapper=null;


   //获取所有管理员
    @Override
    public List<MessageDTO> getList() {
        List<MessageDTO> listDTO =new ArrayList<>();
        List<Message> listPO=iMessageMapper.findMessageByAll();
        for (Message m:listPO) {
            User user=iAdminMangerMapper.findUserById(m.getUserId());
            MessageDTO messageDTO=new MessageDTO(m);
            messageDTO.setUserName(user.getUserName());
            listDTO.add(messageDTO);
        }
        return listDTO;
    }

    @Override
    public MessageDTO getMessageDTO(long id) {
        Message m=iMessageMapper.findMessageById(id);
        MessageDTO messageDTO=new MessageDTO(m);
        return messageDTO;
    }

    @Override
    public String getUserName(long userId) {
        return null;
    }


    //新增
    @Override
    public void addMessage(MessageProfileDTO m) {
        Message message=m.getMessage();
        iMessageMapper.addMessage(message);
    }

    //修改
    @Override
    public void  updataMessage(MessageProfileDTO m) {
        Message message=iMessageMapper.findMessageById(m.getId());
        message.setTitle(m.getTitle());
        message.setContent(m.getContent());
        message.setLink(m.getLink());
        iMessageMapper.updateMessage(message);
    }

    @Override
    public void deleteMessage(long id) {
        iMessageMapper.deleteMessage(id);
    }
}

